package com.hk.controller;

import com.alibaba.fastjson.JSON;
import com.hk.commons.CommonResult;
import com.hk.model.Admin;
import com.hk.model.vo.Result;
import com.hk.utils.JedisUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.Jedis;

import javax.servlet.http.HttpSession;

/**
 * @Author: aerfazhe
 * @Date: 2021/7/8 10:00
 * @Statement: 测试跨域携带Cookie使用
 */
@RestController
@RequestMapping("/s")
public class SSController {

    private Jedis jedis = JedisUtil.getJedis();

    @GetMapping("/test")
    public Result test(HttpSession session) {
//        存储Session
        String s = "admin123";
        session.setAttribute("s",s);
//        redis
    /*    Admin admin = new Admin("sadasdas","121456");
        jedis.set("admin", JSON.toJSONString(admin));*/
        Result result = CommonResult.successResult(s);
        return result;
    }

    @PostMapping("/test1")
    public String test1(HttpSession session) {
//        测试Session跨域后是否可以拿到
        String s = (String) session.getAttribute("s");
        System.out.println("s===="+s);
//        redis
        /*String admin = jedis.get("admin");
        Admin admin1 = JSON.parseObject(admin, Admin.class);
        System.out.println("admin=="+admin1);*/
        return "success";
    }

}
